// pages/find/index.js
var t = getApp(),
c = t.requirejs("api/index"),
a = t.requirejs("core");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    route: "find",
    menu: t.tabBar,
    menu_show: false,
    loaded: false,
    list: [],
    page: 1,
    class_id:'',
    class_id1: '',
    class_id2: '',
    cate_index:'',
    cate:[],
    class_style:2,
    show_class:true
  },
  //底部导航跳转
  menu_url: function (k) {
    a.menu_url(k, 2);
  },
  onLoad: function (e) {
    a.compatible_phonex(this);
    a.setting();
    if (e != null && e != undefined) {
      this.setData({
        tabbar_index: e.tabbar_index ? e.tabbar_index : -1
      });
    }
    this.setData({
      menu: getApp().tabBar,
      class_id: e.id ? e.id:'',
      class_id1: e.id ? e.id : '',
      show_class: e.id ? false : true,
      class_style: e.class_style ? e.class_style:2
    })
    
    if (this.data.tabbar_index >= 0) {
      this.setData({
        showtabbar: true,
      })
    }
      this.getlist();
      this.initCategory();
  
  },
  cate_select: function (t) {

    var that = this,
      cate = that.data.cate,
      data = a.pdata(t),
      e = {};
    console.log(data)
    if (data.level == 1) {
      e['cate_index'] = data.index;
      e['class_id2'] = '';
      if (data.id == '') {
        e.cate2 = [];
      } else {
        e.cate2 = cate[data.index].cate;
      }
    }
    e['class_style'] = data.class_style ? data.class_style:2;
    e['class_id'] = data.id;
    e['class_id' + data.level] = data.id;
    e.list= [];
    e.page= 1;
    e.loaded= false;
    that.setData(e)
    that.getlist();
  },
  /**
*获取分类
* @return array
*/
  initCategory: function () {
    var t = this;
    a.get("Article/ArticleClass", {}, function (a) {
      t.setData({
        cate: a.info,
      })
    })
  },
  /**
     * 获取文章列表信息
     */
  getlist: function () {
    var that = this,
      ident = '',
      class_id = that.data.class_id,
      page = that.data.page;
    c.article_list(ident, page, class_id, that, function (t) {
      that.setData(t)
    })
  },
  /**
    * 下拉刷新
    */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      loaded: false
    })
    this.getlist();
    this.initCategory();
    wx.stopPullDownRefresh();
  },
  /**
   *上拉加载
   */
  onReachBottom: function () {
    console.log('加载更多')
    this.data.loaded || this.getlist()
  },
  to_url:function(e){
 var data=a.pdata(e),url='';
 if(data.link){
   url = '/yb_shop/pages/web/index?url=' + escape(data.link) + '&name=' + data.name;  
 }else{
   url = '/yb_shop/pages/find_info/index?id=' + data.id;
 }
 a.jump(url);
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})